package org.excilys.training.ebanking.DTO;


import java.util.List;

import javax.jws.WebService;

import org.excilys.training.ebanking.DTO.IFactoryDTO;
import org.excilys.training.ebanking.iservice.IServiceCompte;
import org.excilys.training.ebanking.iservice.IServiceOperation;
import org.excilys.training.ebanking.model.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import ebanking_ws_soap.ebankingvirement.EbankingVirement;
import ebanking_ws_soap.ebankingvirement.Operations;

@Component(value="EbankingVirementImpl")
@WebService(endpointInterface="ebanking_ws_soap.ebankingvirement.EbankingVirement")
public class EbankingVirementImpl implements EbankingVirement {

	@Autowired
	private IServiceOperation serviceOperation;

	@Autowired
	private IFactoryDTO factoryDTO;

	@Autowired
	private IServiceCompte serviceCompte;

	@Override
	public Operations consulterVirement(int id) {
		Operations operations = new Operations();
		List<Operation> Listop = serviceOperation.getAllVirementByAccount(id);
		int n = Listop.size();

		for(int i=0;i<n;i++){
			operations.getOperation().add(i, factoryDTO.createOPerationDTO(Listop.get(i))) ;
		}

		return operations;
	}

	@Override
	public void transfertIntern(int idCompteSource, int idCompteCible,
			float montant) {
		final int typeOperation=4;
			serviceCompte.transfertInterne(idCompteSource, idCompteCible, montant, typeOperation);
	}

	@Override
	public void transfertExterne(int idCompteSource, int idCompteCible,
			float montant) {

		final int typeOperation = 5;
		serviceCompte.transfertExterne(idCompteSource, idCompteCible, montant, typeOperation);
	}

}
